package com.ccf.business.etl.flow;

import com.ccf.business.etl.client.DatabaseClient;
import com.ccf.business.etl.model.dto.NodeDTO;
import com.ccf.business.etl.service.IRuleDictService;
import com.ccf.business.etl.service.IRuleGroupService;
import com.ccf.business.etl.service.IRuleSynonymService;
import com.component.api.constants.ComponentCodeConstants;
import com.framework.minio.config.MinioConfig;
import com.framework.minio.service.MinioService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 描述：
 * 参数管理者
 * @author xianggj
 * @Date 2021/11/30 15:45
 **/
@Service
public class ParamManager {

    @Autowired
    private DatabaseClient databaseClient;

    @Autowired
    private IRuleGroupService iRuleGroupService;

    @Autowired
    private IRuleSynonymService iRuleSynonymService;

    @Autowired
    private IRuleDictService iRuleDictService;

    @Autowired
    private MinioConfig minioConfig;

    @Autowired
    private MinioService minioService;

    public ParamHandler getHandler(NodeDTO nodeDTO) {
        String code = nodeDTO.getCode();
        ParamHandler paramHandler = null;
        switch (code){
            case ComponentCodeConstants.DATA_INPUT:
                paramHandler = new DataInputParamHandler();
                break;
            case ComponentCodeConstants.DATA_OUTPUT:
                paramHandler = new DataOutputParamHandler();
                break;
            case ComponentCodeConstants.COLUMN_TRANSFORM:
                paramHandler = new ColumnTransformParamHandler();
                break;
            case ComponentCodeConstants.DATA_TO_A:
                paramHandler = new DataToAParamHandler();
                break;
            case ComponentCodeConstants.DEFAULT_PADDING:
                paramHandler = new DefaultPaddingParamHandler();
                break;
            case ComponentCodeConstants.DICTIONARY_SPECIFICATION:
                paramHandler = new DictionarySpecificationParamHandler();
                break;
            case ComponentCodeConstants.FORMAT_PARSING:
                paramHandler = new FileReadParamHandler();
                break;
            case ComponentCodeConstants.GATHER_MERGE:
                paramHandler = new GatherMergeParamHandler();
                break;
            case ComponentCodeConstants.NUMERICAL_VALIDATION:
                paramHandler = new NumericalValidationParamHandler();
                break;
            case ComponentCodeConstants.OUTLIERS_REMOVE:
                paramHandler = new OutliersRemoveParamHandler();
                break;
            case ComponentCodeConstants.UNIFIED_OUTPUT:
                paramHandler = new UnifiedOutputParamHandler();
                break;
            default:
                return new DefaultParamHandler();
        }
        paramHandler.setDatabaseClient(databaseClient);
        paramHandler.setIRuleDictService(iRuleDictService);
        paramHandler.setIRuleGroupService(iRuleGroupService);
        paramHandler.setIRuleSynonymService(iRuleSynonymService);
        paramHandler.setMinioConfig(minioConfig);
        paramHandler.setMinioService(minioService);
        paramHandler.setNodeDTO(nodeDTO);
        return paramHandler;

    }

}
